package com.trkj.controllers;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.Medcinestore;
import com.trkj.pojos.Staff;
import com.trkj.service.MedcineTypeService;
import com.trkj.service.SSSendDrugsService;

/**
 * 药库发药Controller
 * @author Administrator
 *
 */
@Controller
public class StorageSendDrugsController {
	@Autowired
	private SSSendDrugsService ssSendDrugsService;
	@Autowired
	private MedcineTypeService drugsSer;
	@GetMapping("/to_StorageSendDrugs")
	public String to_StorageSendDrugs() {
		return "ssSendDrugs";
	}
	
	/**
	 * 获取所有药库发药总表信息
	 * @return
	 */
	@GetMapping("/getAllSSsendDrugs")
	@ResponseBody
	public Map getAllSSsendDrugs(int page,int rows) {
		return ssSendDrugsService.getAllSSSendDrugs(page, rows);
	}
	
	/**
	 * 按条件查询药库发药
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@GetMapping("/searchSSSendDrugs")
	@ResponseBody
	public Map getSomeSSsendDrugs(int page,int rows,String startDate,String endDate) {
		System.out.println("----"+page+rows+startDate+endDate);
		Map map = new HashMap<>();
		map.put("startDate", startDate);
		map.put("endDate", endDate);
		return ssSendDrugsService.getSomeSSSendDrugs(page, rows, map);
	}
	
	/**
	 * 按发药名称查询
	 * @param searchSSsendDrugsName
	 * @return
	 */
	@GetMapping("/searchSSsendDrugsName")
	@ResponseBody
	public Map searchSSsendDrugsName(int page,int rows,String searchSSsendDrugsName) {
		System.out.println("searchSSsendDrugsName="+searchSSsendDrugsName);
		Map map = new HashMap<>();
		map.put("name", searchSSsendDrugsName);
		return ssSendDrugsService.searchSSsendDrugsByName(page, rows, map);
	}
	/**
	 * 按条件查询所有药库发药详情Map
	 * @return
	 */
	@GetMapping("/getAllSSsendDrugsDetailsMap")
	@ResponseBody
	public Map getAllSSsendDrugsDetailsMap(int page,int rows,Long sendmedcineDrugstoreId,Long medcineType,Long medcineStore,Long staff) {
		Map map = new HashMap<>();
		map.put("sendmedcineDrugstoreId", sendmedcineDrugstoreId);
		map.put("medcineType", medcineType);
		map.put("medcineStore", medcineStore);
		map.put("staff", staff);
		return ssSendDrugsService.getAllSSsendDrugsDetailsMap(page, rows,map);
	}
	
	/**
	 * 获取所有的药房
	 * @return
	 */
	@GetMapping("/getAllMedcineStore")
	@ResponseBody
	public List<Medcinestore> getAllMedcineStore() {
		return ssSendDrugsService.findAllMedcineStore();
	}
	/**
	 * 获取所有的操作人信息
	 * @return
	 */
	@GetMapping("/getAllStaff")
	@ResponseBody
	public List<Staff> getAllStaff(){
		return ssSendDrugsService.findAllStaff();
	}
	
	/**
	 * 查询单个药品的正常库存
	 * @param medcineName
	 * @return
	 */
	@GetMapping("/SSselectOneDrugsNumber")
	@ResponseBody
	public BigDecimal SSselectOneDrugsNumber(String medcineName) {
		return drugsSer.findOneNumber(medcineName);
	}
	/**
	 * 药库发药成功
	 * @param SSsendDrugsPeople
	 * @param sendmedcineDetailsId
	 */
	@GetMapping("/SSsendDrugsYes")
	@ResponseBody
	public String SSsendDrugsYes(String SSsendDrugsPeople,Long sendmedcineDetailsId,BigDecimal medcineNumber,String medcineName) {
		ssSendDrugsService.SSsendDrugsYes(SSsendDrugsPeople, sendmedcineDetailsId, medcineNumber, medcineName);
		return "";
	}
}
